/**
 * Copyright (C), 2021/8/24 14:05
 *
 * @author 田信坤
 * Author:   TianXinKun
 * Date:     2021/8/24 14:05
 */

package com.cakeshop.utils;

import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Month;
import java.time.Period;
import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
 * @version : 1.0
 * @Author TianXinKun
 * @createTime 2021/8/24 14:05
 * This program is protected by copyright laws.
 */
public class LtsDistance {

    /**
     * 获得球面（地球）计算到店铺之间的距离（坐标可以为WGS84、GCJ02等任何一种坐标，但两个点的坐标类型必须相同）
     *
     * @param lon 终点的经度
     * @param lat 终点的纬度
     * @return 两点之间的距离，单位是米
     */
    public static double getDistance(double lon, double lat) {
        // 计算弧长（d * Math.PI / 180.0）
        double radLat1 = Math.toRadians(119.1989061055404);
        double radLat2 = Math.toRadians(37.11644176049751);
        double a = radLat1 - radLat2;
        double b = Math.toRadians(119.1989061055404) - Math.toRadians(lon);
        double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1)
                * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
        // 取WGS84标准参考椭球中的地球长半径(单位:m)
        s = s * 6378137.0;
        //s = Math.round(s * 10000) / 10000;
        double distance = (long) Math.round(s);
        return distance;
    }

    /**
     * 传入一个时间，求当前时间与传人时间的时间差
     *
     * @return long-单位分钟
     */
    public static double Delta_T(String strdate) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = null;
        try {
            date = sdf.parse(strdate);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        Date thisdate = new Date();
        double dategap = ((date.getTime() - thisdate.getTime()));
        double v = dategap / (1000 * 60 * 60);
        return v;
    }
}
